
************************************************************************************************************************************************
****************************** REPLICATION CODE: RELIGION AND BRAZILIAN POLITICS 
****************************** 2019. Cambridge University Press
****************************** By Amy Erica Smith (amyericas@gmail.com) 

****************************** ANALYSIS OF 2014 FACEBOOK STUDY



****************************************** VARIABLE CODING **************************************************************************************

use "C:\Users\aesmith2\Dropbox\Work\Data\brazil_facebook study 2014\data\final_results.dta", clear

********************************************** CLEAN UP DATA
g finishedsurvey = p36 < .
	drop if finishedsurvey != 1

drop v1-image pg*
rename p1 p1_consent
rename p2 p2_moranobrasil
drop if p1_ == 2 | p2_ == 2
foreach var in p5 p6 p7 p8_1 p9_1 p10_1_2 p10_2_1 p10_3_1 p10_4_1 p10_5_1 p10_6_1 p11_1_1 p11_2_1 p11_3_1 p12 p13_1_1 ///
		p13_2_1 p13_3_1 p14_1_1 p14_2_1 p15 p16_1 p17 p18_1 p19_1 p19_2 p19_3 p19_4 p19_5 p19_6 p19_7 p19_8 p20_1 ///
		p20_2 p20_3 p20_4 p20_5 p20_6 p20_7 p20_8 p21_1 p21_2 p21_3 p21_4 p21_5 p21_6 p21_7 p21_8 p22 p23 p24 p25 ///
		p26 p27_1_1 p27_2_1 p27_3_1 p27_4_1 p27_5_1 p28_1 p28_2 p28_3 p29_1 p29_2 p30 p31 p32 p33 p34 {
	recode `var' (-99=.c)
}
foreach var in p29_1 p29_2 {
	recode `var' (8=7) (9=8)
	replace `var' = `var'-1
}
recode p10_4 (3 = 10)
	replace p10_4 = p10_4-5

********************************************** RELIGION ********************************************** 
recode p6 (2 3 .c = 0) (1=1), g(pentecostal)
recode p6 (1 3 .c = 0) (2=1), g(charismatic)
g pentchar = pentecostal+charismatic

recode p5 (1=1) (2=2) (3 4 5 8 = 4) (6 7 = 3), g(religion)
	lab def religion 1 "Catholic" 2 "Evangelical/Pentecostal" 3 "None" 4 "Other"
	lab val religion religion
	lab var p5 "Religious Affiliation"
recode religion (1=1) (2=3) (3=5) (4=6), g(religion2)
	replace religion2 = 2 if religion == 1 & pentchar == 1
	replace religion2 = 4 if religion == 2 & pentchar == 1
	lab def religion2 1 "Catholic" 2 "Charismatic Catholic" 3 "Evangelical" 4 "Pentecostal" 5 "Other Religion" 6 "None", modify
	lab val religion2 religion2

g catholic = p5 == 1
g evangelical = p5 == 2
g other = p5 == 3 | p5 == 4 | p5 == 5 | p5 == 8
g none = p5 == 6 | p5 == 7
	lab def evangelical 0 "Non-Evangelical" 1 "Evangelical"
	lab val evangelical evangelical 

g churchfreq = (5-p7)/4 if p7 != -99
lab var churchfreq "Church Frequency"

********************************************** SECULAR NORMS
foreach var in p29_1 p29_2 {
	replace `var' = (`var'-1)/6
}
corr p29_1 p29_2 
alpha p29_1 p29_2 
egen nonsecularism = rowmean(p29_1 p29_2)
	g secularism = 1-nonsecularism
	
********************************************** DEMOGRAPHICS
g mulher = p32-1

recode p33 (11 = 0) (12 13 = 1) (14 15 = 2) (16 17 18 = 3) (19 20 = 4), g(edr_fb)
	lab def edr_fb 0 "None" 1 "Primary" 2 "Secondary" 3 "Technical/Some higher" 4 "Higher/Graduate"
	lab val edr_fb edr_fb

lab def p30 1 "White" 2 "Brown" 3 "Black" 4 "Amarela" 5 "Indigenous"
	lab val p30 p30
	lab var p30 "Color/Race"
g white = p30 == 1
g afro = p30 == 2 | p30 == 3
g negro = 2-p31
	
g age = p3+16	
recode age (16/25=1) (26/35=2) (36/45=3) (46/55=4) (56/65=5) (66/110=6), g(edad)
lab def edad 1 "16-25" 2 "26-35" 3 "36-45" 4 "46-55" 5 "56-65" 6 "66+", modify 
lab val edad edad
lab var edad "Age Group"
g edad2 = (edad-1)/5
	
********************************************** POLITICAL ENGAGEMENT
g interest = (p8-1)/6
	lab var interest "Political Interest"
g haspid = 2-p22
	lab var haspid "Has Party ID"
g petista = (p23==75) 


********************************************** EXPERIMENTS
*** JOSE VARGAS EXPERIMENT 
egen josevargascondition = group(i15_1 i15_2 i15_3 i15_4), missing
	recode josevargascondition 5=.
	lab def josevargascondition 1 "Control" 2 "Evangelical leaders" 3 "Catholic leaders" 4 "Active in church"
	lab val josevargascondition josevargascondition 
recode josevargascondition (2/4 = 2), g(josevargascondition2)
	lab def josevargascondition2 1 "Control" 2 "Religious Treatments"
	lab val josevargascondition2 josevargascondition2 
	
recode p15 (2=0), g(vargas_usarbroche)
g vargas_vote = (p16-1)/6 
g vargas_correto = (4-p17)/3 
g vargas_turnout = (p18_1-1)/6 
alpha vargas_vote vargas_usarbroche vargas_correto, item
egen vargas_support = rowmean(vargas_vote vargas_usarbroche)


******* BALANCE
global vars mulher edr catholic evangelical other none churchfreq white afro age interest haspid petista
tabstat $vars, by(josevargascondition)
foreach var in $vars {
	mlogit josevargascondition `var'
}


************************************************************************************************************************************************
************************************************************************************************************************************************
****************************************** ANALYSIS ********************************************************************************************

****************************** FIGURE 7.4: Impact of Candidate Religion on Candidate Support, by Secularism, Facebook 2014
preserve
reg vargas_support i.josevargascondition mulher edr catholic evangelical other none churchfreq white afro age interest haspid petista
	margins i.josevargascondition, post
	parmest, norestore
g candidatetype = _n
	lab def candidatetype 1 "Control" 2 "Evangelical Endorsement" 3 "Catholic Endorsement" 4 "Active in Church"
	lab val candidatetype candidatetype 
graph twoway (bar estimate candidatetype if candidatetype == 1, lcolor(black) fcolor(gs4) barwidth(.5)) ///
			 (bar estimate candidatetype if candidatetype == 2, lcolor(black) fcolor(gs8) barwidth(.5)) ///
			 (bar estimate candidatetype if candidatetype == 3, lcolor(black) fcolor(gs12) barwidth(.5)) ///
			 (bar estimate candidatetype if candidatetype == 4, lcolor(black) fcolor(gs16) barwidth(.5)) ///
			 (rspike min95 max95 candidatetype, lcolor(black)), ///
	graphregion(fcolor(white) lcolor(white)) xlabel(1(1)4, valuelabel notick) xtitle("") legend(off) ///
	ytitle("Candidate Support (0-1 Scale)", margin(small)) ylabel(.25(.05).4, gmin gmax) name(fig1, replace)
restore	
preserve
recode josevargascondition (1 = 0) (2 3 4 = 1), g(jvc2)
reg vargas_support jvc2##c.secularism mulher edr catholic evangelical other none churchfreq white afro age interest haspid petista
	margins i.jvc2, at(secularism=(0 .2 .4 .6 .8 1)) post 
	parmest, norestore level(84)
egen candidatetype = seq(), f(1) t(2)
egen secularism = seq(), f(0) t(5) block(2)
	replace secularism = secularism/5
graph twoway (rarea min84 max84 secularism if candidatetype == 1, lcolor(gs8) fcolor(none)) /// 
			(rarea min84 max84 secularism if candidatetype == 2, lcolor(gs8) fcolor(gs15)) /// 
			(line estimate secularism if candidatetype == 1, lcolor(black)) ///
			(line estimate secularism if candidatetype == 2, lcolor(gs10) lwidth(thick) lpattern(longdash)) , ///
	graphregion(fcolor(white) lcolor(white)) xtitle("Secular Norms", margin(medium)) ///
	legend(order(3 "Control" 4 "Religious Treatments" ) span width(100) symxsize(9) size(small)) name(fig2, replace) 
restore
graph combine fig1 fig2, col(2) xsize(6.5) iscale(1) ///
	graphregion(fcolor(white) lcolor(black)) note("Source: 2014 Facebook Online Experimental Study", span)  
****************************** END FIGURE 7.4: Impact of Candidate Religion on Candidate Support (Take 2), by Secularism, Facebook 2014


